package com.yz.xyt.service.impl;

import com.yz.xyt.domain.Role;
import com.yz.xyt.mapper.RoleMapper;
import com.yz.xyt.service.IRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 角色Service
 * @author JW.WANG
 */
@Service
public class RoleServiceImpl implements IRoleService {
    @Autowired
    RoleMapper roleMapper;


    /**
     * 新增用户角色
     * @param userId
     * @param roleId
     * @return
     */
    @Transactional
    @Override
    public int addUserRole(Long userId, Long roleId) {
        return roleMapper.addUserRole(userId,roleId);
    }

    /**
     * 查询用户角色
     * @param userId
     * @return
     */
    @Override
    public List<String> selectUserRoles(Long userId) {
        return roleMapper.selectUserRoles(userId);
    }

    /**
     * 查询岗位对应的角色
     * @param postNumber
     * @return
     */
    @Override
    public Role selectRoleByPostNumber(String postNumber){
        return roleMapper.selectRoleByPostNumber(postNumber);
    }

    /**
     * 删除用户角色
     * @param userId
     * @return
     */
    @Override
    public int deleteUserRole(Long userId) {
        return roleMapper.deleteUserRole(userId);
    }

    /**
     * 查询角色id
     * @param roleName
     * @return
     */
    @Override
    public String findRoleIdByName(String roleName) {
        return roleMapper.findRoleIdByName(roleName);
    }

    /**
     * 更新用户角色
     * @param id
     * @param roleId
     * @return
     */
    @Override
    public int updateUserRole(Long id, String roleId) {
        return roleMapper.updateUserRole(id,roleId);
    }
}
